package xyf.p01.array_nodelist;

import commons.ListNode;

/**
 * ClassName: P0141_HasCycle
 * Description:
 * Author: xyf
 * Date: 9/7/22 7:46 PM
 * Version: 1.0
 **/
public class P0141_HasCycle
{
    public boolean hasCycle(ListNode head)
    {
        if (head == null || head.next == null)
        {
            return false;
        }

        ListNode slow = head;
        ListNode fast = head.next;

        while (slow != fast)
        {
            if (fast == null || fast.next == null)
            {
                return false;
            }

            fast = fast.next.next;
            slow = slow.next;
        }

        return true;
    }
}
